package com.icinfo.cloud.provider.peripheralinterface.electricinvoice.controller;

import cn.hutool.core.util.ObjectUtil;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.peripheralinterface.electricinvoice.dto.ElectricInvoiceRequest;
import com.icinfo.cloud.provider.peripheralinterface.electricinvoice.service.IElectricInvoiceInterface;
import com.icinfo.framework.common.web.Result;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 描述：电子发票接口前端控制器
 *
 * @author xiangyuyu
 * @date 2022-06-16 16:00
 */
@RestController
@RefreshScope
@RequestMapping("/peripheralInterface/electricInvoice")
@Slf4j
public class ElectricInvoiceInterfaceController {

    @Resource
    private IElectricInvoiceInterface electricInvoiceInterface;



    /**
     * 【V1.3.0】描述：获取电子发票信息
     * @param request {@link ElectricInvoiceRequest}
     * @return Result<List<String>> 获取结果
     * @author xiangyuyu
     * @date 2022-04-08 16:58
     */
    @PostMapping("getElectricInvoice")
    @ApiOperation(value = "【V1.3.0】描述：获取电子发票信息", httpMethod = "POST")
    public Result<List<String>> getElectricInvoice(@RequestBody @Validated ElectricInvoiceRequest request) {

        List<String> list = electricInvoiceInterface.getElectricInvoice(request);
        if(!ObjectUtil.isEmpty(list) && list.size() > 0){
            return Result.success(Constant.STRING_GET_SUCCESS,list);
        } else {
            return Result.error("未获取到对应电子发票信息");
        }
    }

}
